<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>预付款审核页面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var allFundState =${allFundState};
    var allFundPayType = ${allFundPayType};
    var formSetting = {
        title: "预付款业务数据",
        module: 'save',
        numCount: '3',
        columns: [{
            index: "ID",
            name: "id",
            hidden: true,
            label: "id"
        }, {
            index: "BID",
            name: "bid",
            readonly: true,
            label: "预付款编号"
        }, {
            index: "STATE",
            name: "state",
            readonly: true,
            type: "dropdown",
            label: "当前状态"
        }, {
            index: "fundPayType",
            name: "fundPayType",
            readonly: true,
            type: "dropdown",
//            data: allFundState,
            label: "付款方式"
        }, {
            index: "AMOUNT",
            name: "amount",
            readonly: true,
            label: "预付款金额(元)"
        }, {
            index: "TRANSFERCERTIFICATE_ID",
            name: "transferCertificate.id",
            readonly: true,
            label: "TRANSFERCERTIFICATE_ID",
            hidden: true
        }],
        form: {
            'url': 'ajustment-saveOrUpdate',
            'data': function () {
                var id = "${id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "ajustment-find?id=" + id,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                /*做了审核以后有让去直接去更新左侧的数据 不去后台取  直接减一*/
                try {
                    window.top.offlinePayCountReminder.Count__ =
                            (window.top.offlinePayCountReminder.Count__ - 1);
                    window.top.offlinePayCountReminder.load();
                } catch (exe) {
                }
                location.href = 'ajustment-reviewer_main';
            }
        },
        buttons: {
            custom: [{
                id: "reviewOkBtn",
                value: "审核通过",
                click: function () {
                    //提交
                    $("input[name='state']").val("SUCCESS");
                    $("#saveButton").click();
                }
            },{
                id: "reviewRefuseBtn",
                value: "审核拒绝",
                click: function () {
                    //提交
                    $("input[name='state']").val("REFUSE");
                    $("#saveButton").click();
                }
            }, {
                id: "cancelBtn",
                value: "返回",
                click: function () {
                    history.go(-1);
                }
            }]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
        var state = $("input[name='state']");
        var stateDropdown = $("input[name='control_state_dropdown']");
        state.val(state.val() == "" ? "TEMP" : state.val());
        stateDropdown.val(stateUtil.get(allFundState, state.val()));
        var payType = $("input[name='fundPayType']");
        var payTypeDropdown = $("input[name='control_fundPayType_dropdown']");
        payType.val(payType.val() == "" ? "TEMP" : payType.val());
        payTypeDropdown.val(stateUtil.get(allFundPayType, payType.val()));
        $("input[name='amount']").val($("input[name='amount']").val()==""?"0":$("input[name='amount']").val());

        $("#saveButton").hide();
        if (state.val() == "SUCCESS" || state.val() == "REFUSE") {
            $("#reviewOkBtn").hide();
            $("#reviewRefuseBtn").hide();
        }
        $("#reviewOkBtn").css("color", "green");
        $("#reviewRefuseBtn").css("color", "red");
        var transferCertificate = $("input[name='transferCertificate.id']");
        $("#attachmentFrame").attr("src",
                                   "../business/attach-main?type=pay&id="
                                   + (transferCertificate.val() == ''
                                           ? 'null' : transferCertificate.val()));
        $("#attachmentFrame")[0].onload = function () {
            $("#attachmentFrame").contents().find("#mf_container0").hide();
        };
    });
    var stateUtil = {
        get: function (arras, key) {
            for (var a in arras) {
                if (arras[a][1] == key) {
                    return arras[a][0];
                }
            }
        }
    }
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
<fieldset class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
        <a
                href="javascript:void(0)"
                class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
            class="replace-ui-jqgrid-title">水单附件</span>
    </div>
    <iframe id="attachmentFrame" style="width:100%;" scrolling="no" frameborder="0"
            onload="this.height=(this.contentWindow.document.documentElement.scrollHeight)"></iframe>
</fieldset>
</body>
</html>
